<template>
  <van-tabs v-model="curC2Id" @click="navClickHandle">
    <van-tab
      :title="c2.name"
      :key="c2.id"
      :name="c2.id"
      v-for="c2 in categoryL2List"
    >
    </van-tab>
  </van-tabs>
</template>

<script>
export default {
  name: "NavType2",
  props: ["categoryL2List"],
  data() {
    return {
      curC2Id: "",
    };
  },
  mounted() {
    this.curC2Id = this.$route.query.subCategoryId - 0;
  },
  watch: {
    $route: {
      immediate:true,
      handler() {
        console.log(76766);
        if (this.$route.query.subCategoryId) {
          this.curC2Id = this.$route.query.subCategoryId - 0;
        } else if (this.$route.query.categoryId) {
          this.curC2Id = this.$route.query.categoryId - 0;
        }
      },
    },
    categoryL2List(){
      this.$nextTick(()=>{
        if (this.$route.query.subCategoryId) {
          this.curC2Id = this.$route.query.subCategoryId - 0;
        } else if (this.$route.query.categoryId) {
          this.curC2Id = this.$route.query.categoryId - 0;
        }
      })
    }
  },
  methods: {
    updateNavId(id) {
      console.log(id);
      this.curC2Id = id - 0;
    },
    navClickHandle(name, title) {
      this.$router.push({
        path: "/item/list",
        query: {
          subCategoryId: this.curC2Id,
          categoryId: this.$route.query.categoryId,
        },
      });
    },
  },
};
</script>

<style>
</style>